package com.liveneo.stoat.common.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import com.liveneo.stoat.common.util.IdGen;
import com.liveneo.stoat.sys.entity.PrpmUser;
import com.liveneo.stoat.sys.web.utils.UserUtil;
/**
 * 
 *@Description: 实体类的基类
 *@Author:hjt 
 *@Since:2017年1月13日 下午9:49:05 
 *@Version:1.0.0
 */
public class BaseEntity implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
     * 删除标记 - 正常
     */
    public static final Boolean DEL_FLAG_NORMAL = Boolean.TRUE;
    /**
     * 删除标记 - 删除
     */
    public static final Boolean DEL_FLAG_DELETE = Boolean.FALSE;
    private String id;
	//alt + insert
    private String createBy;			//创建者
    private Date createTime;			//创建时间
    private String modifyBy;			//更新者
    private Date modifyTime;			//更新时间
    private Boolean validStatus = DEL_FLAG_NORMAL;  //是否有效  1-有效；0-无效'
    
    public BaseEntity() {
    }
    
    /**
     * 执行新增操作之前需要执行的步骤
     * 在Service类里，调用mapper接口的insert方法以前主动调用
     */
    public void preInsert () {
    	PrpmUser user = UserUtil.getCurrentUser();
        if (user != null) {
            this.createBy = user.getUserName();
            this.modifyBy = user.getUserName();
        }
    	this.setId(IdGen.uuid());
        Date now = Calendar.getInstance().getTime();
        this.setCreateTime(now);
        this.setModifyTime(now);
    }
    
    /**
     * 执行修改操作之前需要执行的步骤
     * 在Service类里，调用mapper接口的update方法以前主动调用
     */
    public void preUpadate () {
    	PrpmUser user = UserUtil.getCurrentUser();
        if (user != null) {
            this.modifyBy = user.getUserName();
        }
        Date now = Calendar.getInstance().getTime();
        this.setModifyTime(now);
    }

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getModifyBy() {
		return modifyBy;
	}

	public void setModifyBy(String modifyBy) {
		this.modifyBy = modifyBy;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public Boolean getValidStatus() {
		return validStatus;
	}

	public void setValidStatus(Boolean validStatus) {
		this.validStatus = validStatus;
	}
}
